<?php
namespace Home\Controller;
require 'vendor/autoload.php';    // 注意位置一定要在 引入ThinkPHP入口文件 之前
use Think\Controller;
use JPush\Client as JPushClient;

class IndexController extends Controller {
     //首页
     public function index(){
        if(session('?username')){
            $this->assign('user',session('username'));
            $this->display('index');
        }
        else{
            $this->login();
        }
    }
     //跳转登陆
     public function login(){
        $this->display('login');
    }

    //验证登陆
    public function loginindex(){
        $username=$_POST['usr'];
        $password=$_POST['pwd'];

        $map['username']=$username;
        $map['password']=$password;
        // $map['role']='01';//限制其他人员登陆后台
        $map['_string']='(role=\'01\' or role=\'08\' or role=\'03\')';


        $info=M()->table('gf_user')->field('id,username,password,role')->where($map)->find();

        if($info){
            session('username',$info['username']);
            session('password',$info['password']);
            session('userid',$info['id']);
            session('role',$info['role']);
            $this->success('登陆成功','Index/index');
        }
        else{
            $this->error('请输入正确的用户名和密码！');
        }
    }

    //注销
    public function loginout(){
        //清空session
        session('username',null);
        session('password',null);
        $this->login();
    }

    
    //修改密码
    public function uppwd(){
        $o_pwd=$_POST['o_pwd'];
        $n_pwd=$_POST['n_pwd'];
        $username=session('username');

        $map['username']=$username;
        $map['password']=$o_pwd;

        $data['password']=$n_pwd;

        $info=M()->table('gf_user')->where($map)->save($data);

        if($info){
            $this->success('密码修改成功');
        }
        else{
            $this->error('密码修改失败，请稍后再试');
        }
    }

    //用户管理
    public function yhgl(){
        if(session('role')=='01'){
            $map['pid']=1;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('yhgl');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }
    
    //查询用户
    public function queryuser(){
        $username=$_POST['username'];
        if(!empty($username)){
            $map['username']=array('like','%'.$username.'%');
        }
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_user')->field('id,username,password,sjzd(role,\'角色\') role,workpace,xm,phone,role as roleid')->where($map)->limit($rows*($page-1),$rows)->select();
        $total=M('gf_user')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //添加用户
    public function adduser(){
        $username=$_POST['username'];
        $password=$_POST['pwd'];
        $xm=$_POST['xm'];
        $phone=$_POST['phone'];
        $workpace=$_POST['workpace'];
        $role=$_POST['role'];

        $data['username']=$username;
        $data['password']=$password;
        $data['xm']=$xm;
        $data['phone']=$phone;
        $data['workpace']=$workpace;
        $data['role']=$role;

        $info=M()->table('gf_user')->data($data)->add();
        if($info>0){
            $this->ajaxreturn('添加用户成功！');
        }
        else{
            $this->ajaxreturn('添加用户失败！');
        }
    }
    //修改用户
    public function edituser(){
        $id=$_POST['hidid'];
        $username=$_POST['username'];
        $password=$_POST['pwd'];
        $xm=$_POST['xm'];
        $phone=$_POST['phone'];
        $workpace=$_POST['workpace'];
        $role=$_POST['role'];

        $map['id']=$id;

        $data['username']=$username;
        $data['password']=$password;
        $data['xm']=$xm;
        $data['phone']=$phone;
        $data['workpace']=$workpace;
        $data['role']=$role;

        $info=M()->table('gf_user')->where($map)->save($data);
        if($info>0){
            $this->ajaxreturn('修改用户成功！');
        }
        else{
            $this->ajaxreturn('修改用户失败！');
        }
    }
    //删除用户
    public function deluser(){
        $id=$_POST['id'];
        $map['id']=$id;
        $info= M()->table('gf_user')->where($map)->delete();
        if($info>0){
            $this->ajaxreturn('删除用户成功！');
        }
        else{
            $this->ajaxreturn('删除用户失败！');
        }
    }
    //数据字典
    public function sjzd(){
        if(session('role')=='01'){
            $map['pid']=1;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('sjzd');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }
    //查询数据字典
    public function querysjzd(){
        $xmmc=$_POST['xmmc'];
        if(!empty($xmmc)){
            $map['oi_name']=$xmmc;
        }
            //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_code')->field('id,oi_name,oi_code,oi_value,param')->where($map)->order('oi_name,param')->limit($rows*($page-1),$rows)->select();
        $total=M('gf_code')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        $this->ajaxreturn($count);
    }
        //添加数据字典
        public function addcode(){
        $oi_name=$_POST['oi_name'];
        $oi_code=$_POST['oi_code'];
        $oi_value=$_POST['oi_value'];
        $param=$_POST['param'];

        $data['oi_name']=$oi_name;
        $data['oi_code']=$oi_code;
        $data['oi_value']=$oi_value;
        $data['param']=$param;

        $info=M()->table('gf_code')->data($data)->add();
        if($info>0){
            $this->ajaxreturn('添加数据字典成功！');
        }
        else{
            $this->ajaxreturn('添加数据字典失败！');
        }
    }
    //修改数据字典
    public function editcode(){
        $id=$_POST['hidid'];
        $oi_name=$_POST['oi_name'];
        $oi_code=$_POST['oi_code'];
        $oi_value=$_POST['oi_value'];
        $param=$_POST['param'];

        $map['id']=$id;

        $data['oi_name']=$oi_name;
        $data['oi_code']=$oi_code;
        $data['oi_value']=$oi_value;
        $data['param']=$param;


        $info=M()->table('gf_code')->where($map)->save($data);
        if($info>0){
            $this->ajaxreturn('修改数据字典成功！');
        }
        else{
            $this->ajaxreturn('修改数据字典失败！');
        }
    }
    //删除数据字典
    public function delcode(){
        $id=$_POST['id'];
        $map['id']=$id;
        $info= M()->table('gf_code')->where($map)->delete();
        if($info>0){
            $this->ajaxreturn('删除数据字典成功！');
        }
        else{
            $this->ajaxreturn('删除数据字典失败！');
        }
    }

    //企业管理
    public function qygl(){
        if(session('role')=='01'){
            $map['pid']=1;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('qygl');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

      //查询企业
      public function queryqy(){
        $name=$_POST['name'];
        if(!empty($name)){
            $map['name']=array('like','%'.$name.'%');
        }
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_company')->field('id,name,province,city,area,dz,linkman,linkphone,fzry,zt,yh(fzry) fzr,sjzd(zt,\'企业状态\') qyzt,concat(province(province),city(city),qy(area),dz) location,sjzd(qylx,\'类型\') lx,qylx,sbsl,img_path')->where($map)->limit($rows*($page-1),$rows)->select();
        $total=M('gf_company')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //添加企业
    public function addqy(){
        $name=$_POST['name'];
        $province=$_POST['province'];
        $city=$_POST['city'];
        $area=$_POST['area'];
        $dz=$_POST['dz'];
        $linkman=$_POST['linkman'];
        $linkphone=$_POST['linkphone'];
        $fzry=$_POST['fzry'];
        $qyzt=$_POST['qyzt'];
        $qylx=$_POST['qylx'];
        $sbsl=$_POST['sbsl'];

        $data['name']=$name;
        $data['province']=$province;
        $data['city']=$city;
        $data['area']=$area;
        $data['dz']=$dz;
        $data['linkman']=$linkman;
        $data['linkphone']=$linkphone;
        $data['fzry']=$fzry;
        $data['zt']=$qyzt;
        $data['qylx']=$qylx;
        $data['sbsl']=$sbsl;

        $info=M()->table('gf_company')->data($data)->add();
        if($info>0){
            $this->ajaxreturn('添加企业成功！');
        }
        else{
            $this->ajaxreturn('添加企业失败！');
        }
    }
    //修改企业
    public function editqy(){
        $id=$_POST['hidid'];
        $name=$_POST['name'];
        $province=$_POST['province'];
        $city=$_POST['city'];
        $area=$_POST['area'];
        $dz=$_POST['dz'];
        $linkman=$_POST['linkman'];
        $linkphone=$_POST['linkphone'];
        $fzry=$_POST['fzry'];
        $qyzt=$_POST['qyzt'];
        $qylx=$_POST['qylx'];
        $sbsl=$_POST['sbsl'];

        $map['id']=$id;

        $data['name']=$name;
        $data['province']=$province;
        $data['city']=$city;
        $data['area']=$area;
        $data['dz']=$dz;
        $data['linkman']=$linkman;
        $data['linkphone']=$linkphone;
        $data['fzry']=$fzry;
        $data['zt']=$qyzt;
        $data['qylx']=$qylx;
        $data['sbsl']=$sbsl;

        $info=M()->table('gf_company')->where($map)->save($data);
        if($info>0){
            $this->ajaxreturn('修改企业成功！');
        }
        else{
            $this->ajaxreturn('修改企业失败！');
        }
    }
    //删除企业
    public function delqy(){
        $id=$_POST['id'];
        $map['id']=$id;
        $info= M()->table('gf_company')->where($map)->delete();
        if($info>0){
            $this->ajaxreturn('删除企业成功！');
        }
        else{
            $this->ajaxreturn('删除企业失败！');
        }
    }

    //添加企业统计图片
    public function addtjpic(){
        $id=$_POST['hidqyid'];
        $map['id']=$id;
        //保存文件
        $upload = new \Think\Upload(); // 实例化上传类
        $upload->rootPath = './Uploads/'; // 设置附件上传根目录
        // 上传文件
        $uploadinfo = $upload->upload();
        if($uploadinfo) {// 存在文件上传成功
            $file_path = "/Uploads/".$uploadinfo['fb']['savepath'].$uploadinfo['fb']['savename'];
            $data['img_path']=$file_path;
            $data['scsj']=time();
            $fileinfo=M()->table('gf_company')->where($map)->save($data);
            if($fileinfo>0){
                $this->ajaxreturn('上传成功！');
            }
            else{
                $this->ajaxreturn('上传失败！');
            }
        }
        else{
            $this->ajaxreturn('图片上传失败！');
        }

    }

    //站房管理
     public function zfgl(){
         if(session('role')=='01'){
            $map['pid']=1;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('zfgl');
            }
         }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

      //查询站房
      public function queryzf(){
        $name=$_POST['name'];
        if(!empty($name)){
            $map['name']=array('like','%'.$name.'%');
        }
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_zf')->field('id,name,ssqy,fzry,zflx,sbsl,yh(fzry) fzr,sjzd(zflx,\'类型\') type,ssqy(ssqy) qymc')->where($map)->limit($rows*($page-1),$rows)->order('ssqy')->select();
        $total=M('gf_zf')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //添加站房
    public function addzf(){
        $name=$_POST['name'];
        $ssqy=$_POST['ssqy'];
        $zflx=$_POST['zflx'];
        $fzry=$_POST['fzry'];
        $sbsl=$_POST['sbsl'];

        $data['name']=$name;
        $data['ssqy']=$ssqy;
        $data['zflx']=$zflx;
        $data['fzry']=$fzry;
        $data['sbsl']=$sbsl;

        $info=M()->table('gf_zf')->data($data)->add();
        if($info>0){
            $this->ajaxreturn('添加站房成功！');
        }
        else{
            $this->ajaxreturn('添加站房失败！');
        }
    }
    //修改站房
    public function editzf(){
        $id=$_POST['hidid'];
        $name=$_POST['name'];
        $ssqy=$_POST['ssqy'];
        $zflx=$_POST['zflx'];
        $fzry=$_POST['fzry'];
        $sbsl=$_POST['sbsl'];

        $map['id']=$id;

        $data['name']=$name;
        $data['ssqy']=$ssqy;
        $data['zflx']=$zflx;
        $data['fzry']=$fzry;
        $data['sbsl']=$sbsl;

        $info=M()->table('gf_zf')->where($map)->save($data);
        if($info>0){
            $this->ajaxreturn('修改站房成功！');
        }
        else{
            $this->ajaxreturn('修改站房失败！');
        }
    }
    //删除站房
    public function delzf(){
        $id=$_POST['id'];
        $map['id']=$id;
        $info= M()->table('gf_zf')->where($map)->delete();
        if($info>0){
            $this->ajaxreturn('删除站房成功！');
        }
        else{
            $this->ajaxreturn('删除站房失败！');
        }
    }

    //站房标准化
    public function zfbzh(){
        if(session('role')=='01'){
            $map['pid']=5;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('zfbzh');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

    
    //查询站房资料
    public function queryzfzl(){
        $bt=$_POST['bt'];
        if(!empty($bt)){
            $map['bt']=array('like','%'.$bt.'%');
        }
        $map['type']='01';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_zl')->field('id,bt,sm,lx,zq,sjzd(lx,\'类型\') zllx')->where($map)->limit($rows*($page-1),$rows)->order('id')->select();
        $total=M('gf_zl')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //添加站房资料
    public function addzfzl(){
        $bt=$_POST['bt'];
        $sm=$_POST['sm'];
        $lx=$_POST['lx'];
        $zq=$_POST['zq'];

        $data['bt']=$bt;
        $data['sm']=$sm;
        $data['lx']=$lx;
        $data['zq']=$zq;
        $data['type']='01';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修

        $info=M()->table('gf_zl')->data($data)->add();
        if($info>0){
            $this->ajaxreturn('添加站房标准化资料成功！');
        }
        else{
            $this->ajaxreturn('添加站房标准化资料失败！');
        }
    }
    //修改站房资料
    public function editzfzl(){
        $id=$_POST['hidid'];
        $bt=$_POST['bt'];
        $sm=$_POST['sm'];
        $lx=$_POST['lx'];
        $zq=$_POST['zq'];

        $map['id']=$id;

        $data['bt']=$bt;
        $data['sm']=$sm;
        $data['lx']=$lx;
        $data['zq']=$zq;

        $info=M()->table('gf_zl')->where($map)->save($data);
        if($info>0){
            $this->ajaxreturn('修改站房标准化资料成功！');
        }
        else{
            $this->ajaxreturn('修改站房标准化资料失败！');
        }
    }
    //删除站房资料
    public function delzfzl(){
        $id=$_POST['id'];
        $map['id']=$id;
        $info= M()->table('gf_zl')->where($map)->delete();
        if($info>0){
            $this->ajaxreturn('删除站房标准化资料成功！');
        }
        else{
            $this->ajaxreturn('删除站房标准化资料失败！');
        }
    }

    //现场资料
    public function xczl(){
        if(session('role')=='01'){
            $map['pid']=5;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('xczl');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

    
    //查询现场资料
    public function queryxczl(){
        $bt=$_POST['bt'];
        if(!empty($bt)){
            $map['bt']=array('like','%'.$bt.'%');
        }
        $map['type']='02';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_zl')->field('id,bt,sm,lx,zq,sjzd(lx,\'类型\') zllx')->where($map)->limit($rows*($page-1),$rows)->order('id')->select();
        $total=M('gf_zl')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //添加现场资料
    public function addxczl(){
        $bt=$_POST['bt'];
        $sm=$_POST['sm'];
        $lx=$_POST['lx'];
        $zq=$_POST['zq'];

        $data['bt']=$bt;
        $data['sm']=$sm;
        $data['lx']=$lx;
        $data['zq']=$zq;
        $data['type']='02';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修

        $info=M()->table('gf_zl')->data($data)->add();
        if($info>0){
            $this->ajaxreturn('添加现场资料成功！');
        }
        else{
            $this->ajaxreturn('添加现场资料失败！');
        }
    }
    //修改现场资料
    public function editxczl(){
        $id=$_POST['hidid'];
        $bt=$_POST['bt'];
        $sm=$_POST['sm'];
        $lx=$_POST['lx'];
        $zq=$_POST['zq'];

        $map['id']=$id;

        $data['bt']=$bt;
        $data['sm']=$sm;
        $data['lx']=$lx;
        $data['zq']=$zq;

        $info=M()->table('gf_zl')->where($map)->save($data);
        if($info>0){
            $this->ajaxreturn('修改现场资料成功！');
        }
        else{
            $this->ajaxreturn('修改现场资料失败！');
        }
    }
    //删除现场资料
    public function delxczl(){
        $id=$_POST['id'];
        $map['id']=$id;
        $info= M()->table('gf_zl')->where($map)->delete();
        if($info>0){
            $this->ajaxreturn('删除现场资料成功！');
        }
        else{
            $this->ajaxreturn('删除现场资料失败！');
        }
    }

    //设备比对
    public function sbbd(){
        if(session('role')=='01'){
            $map['pid']=5;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('sbbd');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

    
    //查询设备比对
    public function querysbbd(){
        $bt=$_POST['bt'];
        if(!empty($bt)){
            $map['bt']=array('like','%'.$bt.'%');
        }
        $map['type']='03';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_zl')->field('id,bt,sm,lx,zq,sjzd(lx,\'类型\') zllx')->where($map)->limit($rows*($page-1),$rows)->order('id')->select();
        $total=M('gf_zl')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //添加设备比对
    public function addsbbd(){
        $bt=$_POST['bt'];
        $sm=$_POST['sm'];
        $lx=$_POST['lx'];
        $zq=$_POST['zq'];

        $data['bt']=$bt;
        $data['sm']=$sm;
        $data['lx']=$lx;
        $data['zq']=$zq;
        $data['type']='03';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修

        $info=M()->table('gf_zl')->data($data)->add();
        if($info>0){
            $this->ajaxreturn('添加设备比对成功！');
        }
        else{
            $this->ajaxreturn('添加设备比对失败！');
        }
    }
    //修改设备比对
    public function editsbbd(){
        $id=$_POST['hidid'];
        $bt=$_POST['bt'];
        $sm=$_POST['sm'];
        $lx=$_POST['lx'];
        $zq=$_POST['zq'];

        $map['id']=$id;

        $data['bt']=$bt;
        $data['sm']=$sm;
        $data['lx']=$lx;
        $data['zq']=$zq;

        $info=M()->table('gf_zl')->where($map)->save($data);
        if($info>0){
            $this->ajaxreturn('修改设备比对成功！');
        }
        else{
            $this->ajaxreturn('修改设备比对失败！');
        }
    }
    //删除设备比对
    public function delsbbd(){
        $id=$_POST['id'];
        $map['id']=$id;
        $info= M()->table('gf_zl')->where($map)->delete();
        if($info>0){
            $this->ajaxreturn('删除设备比对成功！');
        }
        else{
            $this->ajaxreturn('删除设备比对失败！');
        }
    }

    //配件更换
    public function pjgh(){
        if(session('role')=='01'){
            $map['pid']=5;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('pjgh');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

    
    //查询配件更换
    public function querypjgh(){
        $bt=$_POST['bt'];
        if(!empty($bt)){
            $map['bt']=array('like','%'.$bt.'%');
        }
        $map['type']='04';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_zl')->field('id,bt,sm,lx,zq,sjzd(lx,\'类型\') zllx')->where($map)->limit($rows*($page-1),$rows)->order('id')->select();
        $total=M('gf_zl')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //添加配件更换
    public function addpjgh(){
        $bt=$_POST['bt'];
        $sm=$_POST['sm'];
        $lx=$_POST['lx'];
        $zq=$_POST['zq'];

        $data['bt']=$bt;
        $data['sm']=$sm;
        $data['lx']=$lx;
        $data['zq']=$zq;
        $data['type']='04';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修

        $info=M()->table('gf_zl')->data($data)->add();
        if($info>0){
            $this->ajaxreturn('添加配件更换成功！');
        }
        else{
            $this->ajaxreturn('添加配件更换失败！');
        }
    }
    //修改配件更换
    public function editpjgh(){
        $id=$_POST['hidid'];
        $bt=$_POST['bt'];
        $sm=$_POST['sm'];
        $lx=$_POST['lx'];
        $zq=$_POST['zq'];

        $map['id']=$id;

        $data['bt']=$bt;
        $data['sm']=$sm;
        $data['lx']=$lx;
        $data['zq']=$zq;

        $info=M()->table('gf_zl')->where($map)->save($data);
        if($info>0){
            $this->ajaxreturn('修改配件更换成功！');
        }
        else{
            $this->ajaxreturn('修改配件更换失败！');
        }
    }
    //删除配件更换
    public function delpjgh(){
        $id=$_POST['id'];
        $map['id']=$id;
        $info= M()->table('gf_zl')->where($map)->delete();
        if($info>0){
            $this->ajaxreturn('删除配件更换成功！');
        }
        else{
            $this->ajaxreturn('删除配件更换失败！');
        }
    }

     //质控审核-站房标准化
     public function zfbzh_sh(){
        if(session('role')=='01'){
            $map['pid']=11;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('zfbzh_sh');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }
     //质控审核-现场资料
     public function xczl_sh(){
        if(session('role')=='01'){
            $map['pid']=11;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('xczl_sh');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }
     //质控审核-设备比对
     public function sbbd_sh(){
        if(session('role')=='01'){
            $map['pid']=11;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('sbbd_sh');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }
     //质控审核-配件更换
     public function pjgh_sh(){
        if(session('role')=='01'){
            $map['pid']=11;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('pjgh_sh');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

    //查询站房标准化-审核
    public function queryzfbzh_sh(){
        $fzr=$_POST['fzr'];
        $qy=$_POST['qy'];
        $zf=$_POST['zf'];
        $lx=$_POST['lx'];
        $sj=$_POST['sj'];
        $zt=$_POST['zt'];
        $sh=$_POST['sh'];

        if(!empty($fzr)){
            $map['fzr']=$fzr;
        }
        if(!empty($qy)){
            $map['qyid']=$qy;
        }
        if(!empty($zf)){
            $map['zfid']=$zf;
        }
        if(!empty($lx)){
            $map['zflx']=$lx;
        }
        if(!empty($sj)){
            $map['from_unixtime(sj,\'%Y-%m-%d\')']=$sj;
        }
        if(!empty($zt)){
            $map['zt']=$zt;
        }
        $map['zlid']='01';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        if($sh=='01'){
            $map['sfsh']='T';
        }
        else{
            $map['sfsh']=array('exp','is null');
        }
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_pzjl')->field('id,ssqy(qyid) qymc,sjzd(zflx,\'类型\') zflx,zf(zfid) zfmc,sjzd(zlid,\'资料类别\') zllb,btmc(btid) btmc,from_unixtime(sj,\'%Y-%m-%d %H:%i:%s\') scsj,sjzd(zt,\'状态\') ztmc,fzr(fzr) fzr,dqdz,case sfsh when \'T\' then \'已审核\' else \'未审核\' end sfsh')->where($map)->limit($rows*($page-1),$rows)->order('sj desc')->select();
        $total=M('gf_pzjl')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
     //查询现场资料-审核
     public function queryxczl_sh(){
        $fzr=$_POST['fzr'];
        $qy=$_POST['qy'];
        $zf=$_POST['zf'];
        $lx=$_POST['lx'];
        $sj=$_POST['sj'];
        $zt=$_POST['zt'];
        $sh=$_POST['sh'];

        if(!empty($fzr)){
            $map['fzr']=$fzr;
        }
        if(!empty($qy)){
            $map['qyid']=$qy;
        }
        if(!empty($zf)){
            $map['zfid']=$zf;
        }
        if(!empty($lx)){
            $map['zflx']=$lx;
        }
        if(!empty($sj)){
            $map['from_unixtime(sj,\'%Y-%m-%d\')']=$sj;
        }
        if(!empty($zt)){
            $map['zt']=$zt;
        }
        $map['zlid']='02';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        if($sh=='01'){
            $map['sfsh']='T';
        }
        else{
            $map['sfsh']=array('exp','is null');
        }
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_pzjl')->field('id,ssqy(qyid) qymc,sjzd(zflx,\'类型\') zflx,zf(zfid) zfmc,sjzd(zlid,\'资料类别\') zllb,btmc(btid) btmc,from_unixtime(sj,\'%Y-%m-%d %H:%i:%s\') scsj,sjzd(zt,\'状态\') ztmc,fzr(fzr) fzr,dqdz,case sfsh when \'T\' then \'已审核\' else \'未审核\' end sfsh')->where($map)->limit($rows*($page-1),$rows)->order('sj desc')->select();
        $total=M('gf_pzjl')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
     //查询设备比对-审核
     public function querysbbd_sh(){
        $fzr=$_POST['fzr'];
        $qy=$_POST['qy'];
        $zf=$_POST['zf'];
        $lx=$_POST['lx'];
        $sj=$_POST['sj'];
        $zt=$_POST['zt'];

        if(!empty($fzr)){
            $map['fzr']=$fzr;
        }
        if(!empty($qy)){
            $map['qyid']=$qy;
        }
        if(!empty($zf)){
            $map['zfid']=$zf;
        }
        if(!empty($lx)){
            $map['zflx']=$lx;
        }
        if(!empty($sj)){
            $map['from_unixtime(sj,\'%Y-%m-%d\')']=$sj;
        }
        if(!empty($zt)){
            $map['zt']=$zt;
        }
        $map['zlid']='03';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        $map['sfsh']=array('exp','is null');
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_pzjl')->field('id,ssqy(qyid) qymc,sjzd(zflx,\'类型\') zflx,zf(zfid) zfmc,sjzd(zlid,\'资料类别\') zllb,btmc(btid) btmc,from_unixtime(sj,\'%Y-%m-%d %H:%i:%s\') scsj,sjzd(zt,\'状态\') ztmc,fzr(fzr) fzr,dqdz')->where($map)->limit($rows*($page-1),$rows)->order('sj desc')->select();
        $total=M('gf_pzjl')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
     //查询配件更换-审核
     public function querypjgh_sh(){
        $fzr=$_POST['fzr'];
        $qy=$_POST['qy'];
        $zf=$_POST['zf'];
        $lx=$_POST['lx'];
        $sj=$_POST['sj'];
        $zt=$_POST['zt'];

        if(!empty($fzr)){
            $map['fzr']=$fzr;
        }
        if(!empty($qy)){
            $map['qyid']=$qy;
        }
        if(!empty($zf)){
            $map['zfid']=$zf;
        }
        if(!empty($lx)){
            $map['zflx']=$lx;
        }
        if(!empty($sj)){
            $map['from_unixtime(sj,\'%Y-%m-%d\')']=$sj;
        }
        if(!empty($zt)){
            $map['zt']=$zt;
        }
        $map['zlid']='04';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        $map['sfsh']=array('exp','is null');
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_pzjl')->field('id,ssqy(qyid) qymc,sjzd(zflx,\'类型\') zflx,zf(zfid) zfmc,sjzd(zlid,\'资料类别\') zllb,btmc(btid) btmc,from_unixtime(sj,\'%Y-%m-%d %H:%i:%s\') scsj,sjzd(zt,\'状态\') ztmc,fzr(fzr) fzr,dqdz')->where($map)->limit($rows*($page-1),$rows)->order('sj desc')->select();
        $total=M('gf_pzjl')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }

    //查询记录照片
    public function queryphoto(){
        $id=$_POST['id'];
        $map['pz_id']=$id;
        $data=M()->table('gf_zp')->where($map)->select();
        if($data){
            $this->ajaxreturn($data);
        }
    }

    //退回整改
    public function thzg(){
        $id=$_POST['id'];
        $bz=$_POST['bz'];

        //查询拍照记录
        $map['id']=$id;
        $pzjl=M()->table('gf_pzjl')->where($map)->find();
        if($pzjl){
            $data['pzjlid']=$pzjl['id'];
            $data['qyid']=$pzjl['qyid'];
            $data['zflx']=$pzjl['zflx'];
            $data['zfid']=$pzjl['zfid'];
            $data['zlid']=$pzjl['zlid'];
            $data['btid']=$pzjl['btid'];
            $data['fzr']=$pzjl['fzr'];
            $data['bz']=$bz;
            $data['zgsj']=time();
            $data['zt']='01';//01 未整改  02 已整改

            $info=M()->table('gf_pzjl_thzg')->data($data)->add();
            if($info){
                //修改拍照记录状态
                $datapz['zt']='02';// 01 正常  02 退回整改
                $infopz=M()->table('gf_pzjl')->where($map)->save($datapz);
                //生成一条通知消息
                $dataxx['userid']=$pzjl['fzr'];
                $dataxx['title']='拍照记录退回整改';
                $dataxx['content']=$bz;
                $dataxx['sfyd']=0;
                $dataxx['sj']=time();
                $xxinfo=M()->table('gf_message')->data($dataxx)->add();
                //app推送消息
                try{
                    $jpush = new JPushClient(C('JPUSH_APP_KEY'), C('JPUSH_MASTER_SECRET'));
                    $response = $jpush->push()
                        ->setPlatform('android')  //机型 ANDROID
                        ->addAlias($pzjl['fzr'])
                        ->androidNotification('您有一条退回整改的记录。')
                        ->send();
                        $this->ajaxreturn('退回整改成功。');
                }
                catch(\Exception $e){
                    $this->ajaxreturn('推送消息失败'.$e);
                    exit();  
                }
            }
            else{
                $this->ajaxreturn('退回整改失败，请稍后再试。');
            }
        }
        else{
            $this->ajaxreturn('退回整改失败，请稍后再试。');
        }
    }

     //退回整改-站房标准化
     public function zfbzh_thzg(){
        if(session('role')=='01'){
            $map['pid']=16;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('zfbzh_thzg');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }
    //退回整改-现场资料
    public function xczl_thzg(){
        if(session('role')=='01'){
            $map['pid']=16;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('xczl_thzg');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }
    //退回整改-设备比对
    public function sbbd_thzg(){
        if(session('role')=='01'){
            $map['pid']=16;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('sbbd_thzg');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }
    //退回整改-配件更换
    public function pjgh_thzg(){
        if(session('role')=='01'){
            $map['pid']=16;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('pjgh_thzg');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

     //查询站房标准化-整改
     public function queryzfbzh_thzg(){
        $fzr=$_POST['fzr'];
        $qy=$_POST['qy'];
        $zf=$_POST['zf'];
        $lx=$_POST['lx'];
        $zgsj=$_POST['zgsj'];
        $scsj=$_POST['scsj'];
        $zt=$_POST['zt'];


        if(!empty($fzr)){
            $map['fzr']=$fzr;
        }
        if(!empty($qy)){
            $map['qyid']=$qy;
        }
        if(!empty($zf)){
            $map['zfid']=$zf;
        }
        if(!empty($lx)){
            $map['zflx']=$lx;
        }
        if(!empty($zgsj)){
            $map['from_unixtime(zgsj,\'%Y-%m-%d\')']=$zgsj;
        }
        if(!empty($scsj)){
            $map['from_unixtime(scsj,\'%Y-%m-%d\')']=$scsj;
        }
        if(!empty($zt)){
            $map['zt']=$zt;
        }
        $map['zlid']='01';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_pzjl_thzg')->field('id,ssqy(qyid) qymc,sjzd(zflx,\'类型\') zflx,zf(zfid) zfmc,sjzd(zlid,\'资料类别\') zllb,btmc(btid) btmc,from_unixtime(zgsj,\'%Y-%m-%d %H:%i:%s\') zgsj,from_unixtime(scsj,\'%Y-%m-%d %H:%i:%s\') scsj,sjzd(zt,\'整改状态\') ztmc,fzr(fzr) fzr,bz,dqdz')->where($map)->limit($rows*($page-1),$rows)->order('pzjlid')->select();
        $total=M('gf_pzjl_thzg')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //查询现场资料-整改
    public function queryxczl_thzg(){
        $fzr=$_POST['fzr'];
        $qy=$_POST['qy'];
        $zf=$_POST['zf'];
        $lx=$_POST['lx'];
        $zgsj=$_POST['zgsj'];
        $scsj=$_POST['scsj'];
        $zt=$_POST['zt'];


        if(!empty($fzr)){
            $map['fzr']=$fzr;
        }
        if(!empty($qy)){
            $map['qyid']=$qy;
        }
        if(!empty($zf)){
            $map['zfid']=$zf;
        }
        if(!empty($lx)){
            $map['zflx']=$lx;
        }
        if(!empty($zgsj)){
            $map['from_unixtime(zgsj,\'%Y-%m-%d\')']=$zgsj;
        }
        if(!empty($scsj)){
            $map['from_unixtime(scsj,\'%Y-%m-%d\')']=$scsj;
        }
        if(!empty($zt)){
            $map['zt']=$zt;
        }
        $map['zlid']='02';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_pzjl_thzg')->field('id,ssqy(qyid) qymc,sjzd(zflx,\'类型\') zflx,zf(zfid) zfmc,sjzd(zlid,\'资料类别\') zllb,btmc(btid) btmc,from_unixtime(zgsj,\'%Y-%m-%d %H:%i:%s\') zgsj,from_unixtime(scsj,\'%Y-%m-%d %H:%i:%s\') scsj,sjzd(zt,\'整改状态\') ztmc,fzr(fzr) fzr,bz,dqdz')->where($map)->limit($rows*($page-1),$rows)->order('pzjlid')->select();
        $total=M('gf_pzjl_thzg')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //查询设备比对-整改
    public function querysbbd_thzg(){
        $fzr=$_POST['fzr'];
        $qy=$_POST['qy'];
        $zf=$_POST['zf'];
        $lx=$_POST['lx'];
        $zgsj=$_POST['zgsj'];
        $scsj=$_POST['scsj'];
        $zt=$_POST['zt'];


        if(!empty($fzr)){
            $map['fzr']=$fzr;
        }
        if(!empty($qy)){
            $map['qyid']=$qy;
        }
        if(!empty($zf)){
            $map['zfid']=$zf;
        }
        if(!empty($lx)){
            $map['zflx']=$lx;
        }
        if(!empty($zgsj)){
            $map['from_unixtime(zgsj,\'%Y-%m-%d\')']=$zgsj;
        }
        if(!empty($scsj)){
            $map['from_unixtime(scsj,\'%Y-%m-%d\')']=$scsj;
        }
        if(!empty($zt)){
            $map['zt']=$zt;
        }
        $map['zlid']='03';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_pzjl_thzg')->field('id,ssqy(qyid) qymc,sjzd(zflx,\'类型\') zflx,zf(zfid) zfmc,sjzd(zlid,\'资料类别\') zllb,btmc(btid) btmc,from_unixtime(zgsj,\'%Y-%m-%d %H:%i:%s\') zgsj,from_unixtime(scsj,\'%Y-%m-%d %H:%i:%s\') scsj,sjzd(zt,\'整改状态\') ztmc,fzr(fzr) fzr,bz,dqdz')->where($map)->limit($rows*($page-1),$rows)->order('pzjlid')->select();
        $total=M('gf_pzjl_thzg')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //查询配件更换-整改
    public function querypjgh_thzg(){
        $fzr=$_POST['fzr'];
        $qy=$_POST['qy'];
        $zf=$_POST['zf'];
        $lx=$_POST['lx'];
        $zgsj=$_POST['zgsj'];
        $scsj=$_POST['scsj'];
        $zt=$_POST['zt'];


        if(!empty($fzr)){
            $map['fzr']=$fzr;
        }
        if(!empty($qy)){
            $map['qyid']=$qy;
        }
        if(!empty($zf)){
            $map['zfid']=$zf;
        }
        if(!empty($lx)){
            $map['zflx']=$lx;
        }
        if(!empty($zgsj)){
            $map['from_unixtime(zgsj,\'%Y-%m-%d\')']=$zgsj;
        }
        if(!empty($scsj)){
            $map['from_unixtime(scsj,\'%Y-%m-%d\')']=$scsj;
        }
        if(!empty($zt)){
            $map['zt']=$zt;
        }
        $map['zlid']='04';//01 站房标准化  02 现场资料  03 设备比对  04 配件维修
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_pzjl_thzg')->field('id,ssqy(qyid) qymc,sjzd(zflx,\'类型\') zflx,zf(zfid) zfmc,sjzd(zlid,\'资料类别\') zllb,btmc(btid) btmc,from_unixtime(zgsj,\'%Y-%m-%d %H:%i:%s\') zgsj,from_unixtime(scsj,\'%Y-%m-%d %H:%i:%s\') scsj,sjzd(zt,\'整改状态\') ztmc,fzr(fzr) fzr,bz,dqdz')->where($map)->limit($rows*($page-1),$rows)->order('pzjlid')->select();
        $total=M('gf_pzjl_thzg')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }

     //查询记录照片-退回整改
     public function queryphoto_thzg(){
        $id=$_POST['id'];
        $map['pz_id']=$id;
        $data=M()->table('gf_zp_thzg')->where($map)->select();
        if($data){
            $this->ajaxreturn($data);
        }
    }

    
    //药品分发
    public function yjff(){
        if(session('role')=='08'){
            $map['pid']=21;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('yjff');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

     //查询药剂分发
     public function queryyjff(){
        $lqr=$_POST['lqr'];
        $sflq=$_POST['sflq'];

        if(!empty($lqr)){
            $map['userid']=$lqr;
        }
        if(!empty($sflq)){
            $map['sflq']=$sflq;
        }
        else{
            $map['sflq']='F';
        }
        
        $map['sfjj']='T';
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_yjlq')->field('id,lb,yh(userid) lqr,from_unixtime(sj,\'%Y-%m-%d %H:%i:%s\') sj,bz,sjzd(sflq,\'是否领取\') sflq')->where($map)->limit($rows*($page-1),$rows)->order('sj')->select();
        $total=M('gf_yjlq')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }

    //查询药剂领取明细
    public function queryyjlqmx(){
        $id=$_POST['id'];

        if(!empty($id)){
            $map['lqid']=$id;
        }

        $data=M()->table('gf_yjlq_mx')->field('id,lqid,mc,jl,syjl,0 as ffjl')->where($map)->select();

        if($data){
            $this->ajaxreturn($data);
        }
    }

    //修改药剂领取状态
    public function setyjlqzt(){
        $id=$_POST['id'];

        if(!empty($id)){
            $map['id']=$id;
        }

        $data['sflq']='T';

        $info=M()->table('gf_yjlq')->where($map)->save($data);

        if($info){
            $this->ajaxreturn('提交成功!');
        }
        else{
            $this->ajaxreturn('提交失败，请稍后再试。');
        }
    }

     //药品分发-应急
     public function yjyjff(){
        if(session('role')=='08'){
            $map['pid']=21;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('yjyjff');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

    //查询药剂分发-应急
    public function queryyjyjff(){
        $lqr=$_POST['lqr'];
        $sflq=$_POST['sflq'];

        if(!empty($lqr)){
            $map['userid']=$lqr;
        }
        if(!empty($sflq)){
            $map['sflq']=$sflq;
        }
        else{
            $map['sflq']='F';
        }
        
        $map['sfjj']='T';
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_yjyjlq')->field('id,lb,yh(userid) lqr,from_unixtime(sj,\'%Y-%m-%d %H:%i:%s\') sj,bz,sjzd(sflq,\'是否领取\') sflq')->where($map)->limit($rows*($page-1),$rows)->order('sj')->select();
        $total=M('gf_yjyjlq')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        if($count){
            $this->ajaxreturn($count);
        }
    }
    //查询药剂领取明细-应急
    public function queryyjyjlqmx(){
        $id=$_POST['id'];

        if(!empty($id)){
            $map['yjlqid']=$id;
        }

        $data=M()->table('gf_yjyjlq_mx')->field('id,yjlqid,mc,jl,syjl,0 as ffjl')->where($map)->select();

        if($data){
            $this->ajaxreturn($data);
        }
    }

    //修改药剂领取状态-应急
    public function setyjyjlqzt(){
        $id=$_POST['id'];

        if(!empty($id)){
            $map['id']=$id;
        }

        $data['sflq']='T';

        $info=M()->table('gf_yjyjlq')->where($map)->save($data);

        if($info){
            $this->ajaxreturn('提交成功!');
        }
        else{
            $this->ajaxreturn('提交失败，请稍后再试。');
        }
    }

      //药品查询统计
      public function yjcxtj(){
        if(session('role')=='08'){
            $map['pid']=21;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('yjcxtj');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }


    //审核通过
    public function shtg(){
        $id=$_POST['id'];
        $map['id']=$id;

        $data['sfsh']='T';

        $info=M()->table('gf_pzjl')->where($map)->save($data);

        if($info){
            $this->ajaxreturn('审核成功!');
        }
        else{
            $this->ajaxreturn('审核失败，请稍后再试。');
        }
    }

    //增加分发记录
    public function addyjffjl(){
        $lqjlid=$_POST['lqjlid'];
        $lqmxid=$_POST['lqmxid'];
        $mc=$_POST['mc'];
        $ffjl= (float)$_POST['ffjl'];
        $syjl= (float)$_POST['syjl'];

        $data['sj']=time();
        $data['jl']=$ffjl;
        $data['lqid']=$lqjlid;
        $data['mc']=$mc;

        $info=M()->table('gf_yjff_mx')->data($data)->add();

        $map['id']=$lqmxid;
        $data1['syjl']=$syjl-$ffjl;

        $info1=M()->table('gf_yjlq_mx')->where($map)->save($data1);

        if($info){
            $this->ajaxreturn('添加成功!');
        }
        else{
            $this->ajaxreturn('添加失败，请稍后再试。');
        }
    }

     //增加分发记录（应急）
     public function addyjyjffjl(){
        $lqjlid=$_POST['lqjlid'];
        $lqmxid=$_POST['lqmxid'];
        $mc=$_POST['mc'];
        $ffjl= (float)$_POST['ffjl'];
        $syjl= (float)$_POST['syjl'];

        $data['sj']=time();
        $data['jl']=$ffjl;
        $data['yjlqid']=$lqjlid;
        $data['mc']=$mc;

        $info=M()->table('gf_yjyjff_mx')->data($data)->add();

        $map['id']=$lqmxid;
        $data1['syjl']=$syjl-$ffjl;

        $info1=M()->table('gf_yjyjlq_mx')->where($map)->save($data1);

        if($info){
            $this->ajaxreturn('添加成功!');
        }
        else{
            $this->ajaxreturn('添加失败，请稍后再试。');
        }
    }

    //查询药剂分发明细
    public function queryyjffmx(){
        $id=$_POST['id'];

        if(!empty($id)){
            $map['lqid']=$id;
        }

        $data=M()->table('gf_yjff_mx')->field('mc,jl,from_unixtime(sj,\'%Y-%m-%d %H:%i:%s\') sj')->where($map)->order('sj desc')->select();

        if($data){
            $this->ajaxreturn($data);
        }
    }

    //查询应急药剂分发明细
    public function queryyjyjffmx(){
        $id=$_POST['id'];

        if(!empty($id)){
            $map['yjlqid']=$id;
        }

        $data=M()->table('gf_yjyjff_mx')->field('mc,jl,from_unixtime(sj,\'%Y-%m-%d %H:%i:%s\') sj')->where($map)->order('sj desc')->select();

        if($data){
            $this->ajaxreturn($data);
        }
    }


    //药剂清单
    public function yjqd(){
        if(session('role')=='01'||session('role')=='03'){
            $map['pid']=21;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('yjqd');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }
    //查询药剂清单
    public function queryyjqd(){
        $lb=$_POST['lb'];
        if(!empty($lb)){
            $map['lb']=$lb;
        }
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_sjqd')->field('id,lb,mc,bz')->where($map)->order('lb')->limit($rows*($page-1),$rows)->select();
        $total=M('gf_sjqd')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        $this->ajaxreturn($count);
    }
    //添加药剂清单
    public function addyjqd(){
        $lb=$_POST['lb'];
        $mc=$_POST['mc'];
        $bz=$_POST['bz'];

        $data['lb']=$lb;
        $data['mc']=$mc;
        $data['bz']=$bz;

        $info=M()->table('gf_sjqd')->data($data)->add();
        if($info>0){
            $this->ajaxreturn('添加药剂清单成功！');
        }
        else{
            $this->ajaxreturn('添加药剂清单失败！');
        }
    }
    //修改药剂清单
    public function edityjqd(){
        $id=$_POST['hidid'];
        $lb=$_POST['lb'];
        $mc=$_POST['mc'];
        $bz=$_POST['bz'];

        $map['id']=$id;

        $data['lb']=$lb;
        $data['mc']=$mc;
        $data['bz']=$bz;


        $info=M()->table('gf_sjqd')->where($map)->save($data);
        if($info>0){
            $this->ajaxreturn('修改药剂清单成功！');
        }
        else{
            $this->ajaxreturn('修改药剂清单失败！');
        }
    }
    //删除药剂清单
    public function delyjqd(){
        $id=$_POST['id'];
        $map['id']=$id;
        $info= M()->table('gf_sjqd')->where($map)->delete();
        if($info>0){
            $this->ajaxreturn('删除药剂清单成功！');
        }
        else{
            $this->ajaxreturn('删除药剂清单失败！');
        }
    }

     //领取管理
     public function lqgl(){
        if(session('role')=='01'||session('role')=='08'){
            $map['pid']=21;
            $info=M()->table('gf_module')->where($map)->order('px')->select();
            if($info){
                $this->assign('menulist',$info);
                $this->assign('user',session('username'));
                $this->display('lqgl');
            }
        }
        else{
            $this->error('对不起！您没有此模块的操作权限...');
        }
    }

     //领取管理
     public function querylqgl(){
        $lb=$_POST['lb'];
        if(!empty($lb)){
            $map['lb']=$lb;
        }
        $map['sfhz']='F';
        //计算总共有多少页
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $data=M()->table('gf_yjlq')->field('id,lb,yh(userid) user,FROM_UNIXTIME(sj,\'%Y-%m-%d %H:%i:%s\') sj,bz')->where($map)->order('lb')->limit($rows*($page-1),$rows)->select();
        $total=M('gf_yjlq')->where($map)->count();
        $count=array();
        $count['total']=$total;
        $count['rows']=$data;
        $this->ajaxreturn($count);
    }

     //领取管理明细
     public function querylqglmx(){
        $lqid=$_POST['lqid'];
        
        $map['lqid']=$lqid;
       
        $data=M()->table('gf_yjlq_mx')->field('id,lqid,mc,jl')->where($map)->select();

        $this->ajaxreturn($data);
    }

    //修改领取明细
    public function xglqmxbyid(){
        $id=$_POST['id'];
        $jl=$_POST['jl'];

        $data['jl']=$jl;
        $data['syjl']=$jl;

        $map['id']=$id;

        $info=M()->table('gf_yjlq_mx')->where($map)->save($data);

        if($info){
            $this->ajaxreturn('修改成功！');
        }
        else{
            $this->ajaxreturn('修改失败，请稍后再试。');
        }
    } 

}